package com.beiye.drivertransport.curriulum;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.SignActivity;
import com.beiye.drivertransport.SubActivity.SignCourseActivity;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.adapter.ListBaseAdapter;
import com.beiye.drivertransport.adapter.SuperViewHolder;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.SpecifiedLearnIngHomeBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.HelpUtil;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.beiye.drivertransport.utils.WechatShareManager;
import com.githang.statusbar.StatusBarCompat;
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
import com.github.jdsjlzx.interfaces.OnRefreshListener;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

//日常培训学习计划记录
public class SpecifiedLearnRecordActivity extends TwoBaseAty {


    ImageView img_safeback;

    LRecyclerView lv_specified;

    View empty_view;
    //    @Bind(R.id.tv_company)
//    TextView tv_company;
//    @Bind(R.id.tv_name)
//    TextView tv_name;
    private int firstIndex = 1;
    private int pageSize = 15;
    private SpecifiedLearningHomeApt specifiedLearningHomeApt;
    private LRecyclerViewAdapter lRecyclerViewAdapter1;
    ArrayList<SpecifiedLearnIngHomeBean.RowsBean> specifielist = new ArrayList<>();
    ArrayList<SpecifiedLearnIngHomeBean.RowsBean> specifielist1 = new ArrayList<>();
    private List<SpecifiedLearnIngHomeBean.RowsBean> rowList;
    private Bitmap bitmap;


    @Override
    public int getLayoutId() {
        return R.layout.activity_specified_learn_record;
    }

    public void onClick(View view) {
        if (view.getId() == R.id.img_safeback) {
            finish();
        }
    }

    @Override
    public void initData() {
        img_safeback = (ImageView) findViewById(R.id.img_safeback);
        lv_specified = (LRecyclerView) findViewById(R.id.listview_message);
        empty_view = (View) findViewById(R.id.empty_view);
        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        bitmap= HelpUtil.getBitmap(this,R.drawable.logo_share);
        initUi();
    }

    private void initUi() {
        LinearLayoutManager ms = new LinearLayoutManager(SpecifiedLearnRecordActivity.this);
        ms.setOrientation(LinearLayoutManager.VERTICAL);
        lv_specified.setLayoutManager(ms);
        specifiedLearningHomeApt = new SpecifiedLearningHomeApt(SpecifiedLearnRecordActivity.this);

        lRecyclerViewAdapter1 = new LRecyclerViewAdapter(specifiedLearningHomeApt);
        lv_specified.setAdapter(lRecyclerViewAdapter1);
        lv_specified.setFooterViewColor(R.color.colorAccent, R.color.dark, android.R.color.white);
        lv_specified.setFooterViewHint("拼命加载中", "已经全部为你呈现了", "网络不给力啊，点击再试一次吧");
        lv_specified.setOnRefreshListener(new OnRefreshListener() {

            @Override
            public void onRefresh() {
                firstIndex = 1;
                requestData();
            }
        });

        lv_specified.setOnLoadMoreListener(new OnLoadMoreListener() {

            @Override
            public void onLoadMore() {
                firstIndex += pageSize;
                requestData();
            }
        });
        empty_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lv_specified.refresh();
            }
        });

//        lRecyclerViewAdapter1.setOnItemClickListener(new com.github.jdsjlzx.interfaces.OnItemClickListener() {
//            @Override
//            public void onItemClick(View view, int position) {
//                if (Utils.isFastDoubleClick()) {
//                    return;
//                }
//                    SharedPreferences sp1 = getSharedPreferences("SpecifiedLearningHomeActivity", Context.MODE_PRIVATE);
//                    int mark = sp1.getInt("Mark", 1);
//                    if (mark == 0) {
//                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SpecifiedLearningHomeActivity.this);
//                        builder1.setMessage("您已被企业管理员禁用,请联系企业管理员");
//                        builder1.setTitle("提示:");
//                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
//                            public void onClick(DialogInterface dialog, int which) {
//                                dialog.dismiss();
//                                //设置你的操作事项
//                            }
//                        });
//                        builder1.create().show();
//                        return;
//                    }
//
//
//
//            }
//        });
        lv_specified.refresh();
    }

    @Override
    public void requestData() {
        Bundle bundle = getIntent().getExtras();
        String orgId = bundle.getString("orgId");
        SharedPreferences sp1 = getSharedPreferences("SpecifiedLearnRecordActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit1 = sp1.edit();
        edit1.putString("orgId", orgId);
        edit1.commit();
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userId = data.getUserId();
        new Login().getSpecifiedLearningTwo(orgId, userId, 1, 0, firstIndex, pageSize, this, 1);
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 1) {
            SpecifiedLearnIngHomeBean specifiedLearnIngHomeBean = JSON.parseObject(result, SpecifiedLearnIngHomeBean.class);
            if (specifiedLearnIngHomeBean != null) {
                try {

                    if (specifiedLearnIngHomeBean.getRows() != null && specifiedLearnIngHomeBean.getRows().size() > 0) {
                        lv_specified.setVisibility(View.VISIBLE);
                        if (firstIndex == 1) {
                            specifiedLearningHomeApt.clear();
                            specifiedLearningHomeApt.setDataList(specifiedLearnIngHomeBean.getRows());
                        } else {
                            specifiedLearningHomeApt.addAll(specifiedLearnIngHomeBean.getRows());
                        }

                        if (specifiedLearnIngHomeBean.getRows().size() < pageSize) {
                            lv_specified.setNoMore(true);
                        }
                    } else {
                        if (firstIndex == 1) {//第一页
                            lv_specified.setEmptyView(empty_view);
                            specifiedLearningHomeApt.clear();
                        } else {
                            lv_specified.setNoMore(true);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                lv_specified.refreshComplete(specifiedLearnIngHomeBean.getRows() == null ? 0 : specifiedLearnIngHomeBean.getRows().size());
                lRecyclerViewAdapter1.notifyDataSetChanged();
            }
        }
        super.onSuccess(result, call, response, what);
    }

    public class SpecifiedLearningHomeApt extends ListBaseAdapter<SpecifiedLearnIngHomeBean.RowsBean> {
        protected Context context = null;

        public SpecifiedLearningHomeApt(Context context) {
            super(context);
            this.context = context;
        }

        @Override
        public int getLayoutId() {
            return R.layout.specifiedlearning_item_layout;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, final int position) {
            final SpecifiedLearnIngHomeBean.RowsBean rowsBean = getDataList().get(position);

            TextView tv_chNo = holder.getView(R.id.tv_chNo);
            TextView tv_title = holder.getView(R.id.tv_title);
            TextView tv_yes = holder.getView(R.id.tv_parent4);//完成情况
            TextView tv_sign = holder.getView(R.id.tv_parent8);//签名情况
            TextView tv_check = holder.getView(R.id.tv_parent5);//审核情况
            TextView tv_Spotcheck = holder.getView(R.id.tv_parent7);//抽查情况
            TextView tv_actualChLength = holder.getView(R.id.tv_time);//实际学习时间
            // TextView tv_setChLength =  holder.getView(R.id.tv_time1);//计划学习时间
            TextView tv_line_specified = holder.getView(R.id.tv_line_specified);//背景条
            ImageView img_share = holder.getView(R.id.img_share);
            RelativeLayout re_specified1 = holder.getView(R.id.re_specified1);
            final int chNo = rowsBean.getChNo();
            final String chName = rowsBean.getChName();
            re_specified1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (Utils.isFastClicker()) {
                        return;
                    }
                    SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                            Context.MODE_PRIVATE);
                    String orgId = sp.getString("orgId", "");
                    int sn = rowsBean.getSn();
                    int actualChLength = rowsBean.getActualChLength();
                    int setChLength = 0;
setChLength=(rowsBean.getMiNo()>rowsBean.getSetChLength())?rowsBean.getMiNo():rowsBean.getSetChLength();
                    int checkMark = rowsBean.getCheckMark();
                    int finishMark = rowsBean.getFinishMark();
                    Integer qpSn = rowsBean.getQpSn();
                    Bundle bundle = new Bundle();
                    bundle.putString("orgId", orgId);
                    bundle.putInt("sn", sn);
                    bundle.putString("chName", chName);
                    bundle.putInt("actualChLength", actualChLength);
                    bundle.putInt("setChLength", setChLength);
                    bundle.putInt("checkMark", checkMark);
                    bundle.putInt("finishMark", finishMark);
                    bundle.putInt("chNo", chNo);
                    bundle.putInt("rtype",rowsBean.getOtpSn());
                    if (qpSn == null) {
                        bundle.putInt("qpSn", 0);
                    } else {

                        bundle.putInt("qpSn", qpSn);
                    }
                    startActivity(SubSpecifiedLearnRecordActivity.class, bundle);

                }
            });
            final TextView tv_specified_learning = holder.getView(R.id.tv_specified_learning);//学习/签名

            if (chNo == 0) {
                tv_chNo.setText("学时");
            } else {
                tv_chNo.setText(chNo + "学时");
            }
            if (chName == null) {
                tv_title.setText("");
            } else {
                tv_title.setText(chName);
            }

            int finishMark = rowsBean.getFinishMark();
            final Integer qpSn = rowsBean.getQpSn();
            if (finishMark == 0) {//未完成
                int actualChLength = rowsBean.getActualChLength();
                int setChLength = 0;
setChLength=(rowsBean.getMiNo()>rowsBean.getSetChLength())?rowsBean.getMiNo():rowsBean.getSetChLength();
                if (actualChLength == 0 || setChLength == 0) {
                    tv_actualChLength.setText("0%");
                    tv_actualChLength.setTextColor(SpecifiedLearnRecordActivity.this.getResources().getColor(R.color.bixue_red));
                    tv_specified_learning.setText("学习");
                    tv_line_specified.setBackgroundResource(R.color.specified_red);
                    img_share.setVisibility(View.INVISIBLE);
                    tv_yes.setText("未完成");
                    tv_yes.setBackgroundResource(R.drawable.shape_specified_nored);
                    tv_check.setVisibility(View.GONE);
                    tv_sign.setVisibility(View.GONE);

                } else {
                    float studyper = (float) actualChLength / (float) setChLength;
                    if (studyper < 1) {
                        int studyper1 = (int) (studyper * 100);
                        //  String ss = String.format("%1.2f", studyper1);
                        tv_actualChLength.setText(studyper1 + "%");
                        tv_actualChLength.setTextColor(SpecifiedLearnRecordActivity.this.getResources().getColor(R.color.bixue_red));
                        tv_specified_learning.setText("学习");
                        tv_line_specified.setBackgroundResource(R.color.specified_red);
                        img_share.setVisibility(View.INVISIBLE);
                        tv_yes.setText("未完成");
                        tv_yes.setBackgroundResource(R.drawable.shape_specified_nored);
                        tv_check.setVisibility(View.GONE);
                        tv_sign.setVisibility(View.GONE);

                    } else {//未完成 实际时间大于计划时间 判断是qpSn否有值
                        if (qpSn == null) {
                            tv_specified_learning.setText("学习");
                            tv_line_specified.setBackgroundResource(R.color.specified_red);
                            img_share.setVisibility(View.INVISIBLE);
                            tv_yes.setText("未完成");
                            tv_yes.setBackgroundResource(R.drawable.shape_specified_nored);
                            tv_check.setVisibility(View.GONE);
                            tv_sign.setVisibility(View.GONE);
                            tv_actualChLength.setText(99 + "%");
                            tv_actualChLength.setTextColor(SpecifiedLearnRecordActivity.this.getResources().getColor(R.color.bixue_red));
                        } else {
                            tv_specified_learning.setText("考试");
                            tv_line_specified.setBackgroundResource(R.color.holetotal_yellow);
                            img_share.setVisibility(View.INVISIBLE);
                            tv_yes.setText("已完成");
                            tv_yes.setBackgroundResource(R.drawable.shape_specified_dai);
                            tv_check.setVisibility(View.GONE);
                            tv_sign.setVisibility(View.GONE);
                            tv_actualChLength.setText(100 + "%");
                            tv_actualChLength.setTextColor(SpecifiedLearnRecordActivity.this.getResources().getColor(R.color.holetotal_yellow));
                        }


                    }
                }
            } else {//已完成
                final String signPicUrl = HelpUtil.judgeStrNull(rowsBean.getSignPicUrl());
                int checkMark = rowsBean.getCheckMark();
                if (qpSn == null) {
                    if (checkMark == 1 || checkMark == 2) {
                        if (signPicUrl.equals("")) {
                            tv_specified_learning.setVisibility(View.VISIBLE);
                            tv_specified_learning.setText("签名");
                        } else {
                            tv_specified_learning.setVisibility(View.VISIBLE);
                            tv_specified_learning.setText("查看签名");
                        }
                    } else if (checkMark == 0) {
                        if (finishMark == 1) {
                            tv_specified_learning.setVisibility(View.VISIBLE);
                            tv_specified_learning.setText("签名");
                        } else if (finishMark == 2) {
                            tv_specified_learning.setVisibility(View.VISIBLE);
                            tv_specified_learning.setText("查看签名");
                        }

                    }
                } else {
                    tv_specified_learning.setVisibility(View.VISIBLE);
                    tv_specified_learning.setText("考试");
                }

                tv_actualChLength.setText(100 + "%");
                tv_actualChLength.setTextColor(SpecifiedLearnRecordActivity.this.getResources().getColor(R.color.holetotal_gray));
            }

            if (rowsBean.getSpotCheckMark() == 1) {
                tv_Spotcheck.setVisibility(View.VISIBLE);
                tv_Spotcheck.setText("通过抽查");
                tv_Spotcheck.setBackgroundResource(R.drawable.shape_specified_yes);
            } else if (rowsBean.getSpotCheckMark() == 2) {
                tv_Spotcheck.setVisibility(View.VISIBLE);
                tv_Spotcheck.setText("未通过抽查");
                tv_Spotcheck.setBackgroundResource(R.drawable.shape_specified_nored);
            } else {
                tv_Spotcheck.setVisibility(View.INVISIBLE);
            }


            if (rowsBean.getCheckMark() == 2) {
                tv_line_specified.setBackgroundResource(R.color.specified_red);
                tv_check.setVisibility(View.VISIBLE);
                tv_check.setText("审核未通过");
                tv_check.setBackgroundResource(R.drawable.shape_specified_nored);
                tv_yes.setText("已完成");
                img_share.setVisibility(View.VISIBLE);
                tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                tv_sign.setVisibility(View.VISIBLE);
                final String signPicUrl = HelpUtil.judgeStrNull(rowsBean.getSignPicUrl());

                if (signPicUrl.equals("")) {
                    tv_sign.setText("未签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_noorange);

                    //   tv_specified_learning.setText("签名");

                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            if (tv_specified_learning.getText().toString().trim().equals("签名")) {
                                showToast("学习记录不操作签名");
                                return;
                            } else if (tv_specified_learning.getText().toString().trim().equals("考试")) {
                                int sn = rowsBean.getSn();
                                SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                String orgId = sp.getString("orgId", "");
                                Bundle bundle = new Bundle();
                                bundle.putString("orgId", orgId);
                                bundle.putInt("qpSn", qpSn);
                                bundle.putInt("learnsn", sn);
                                startActivity(DailyTrainingExaminationItemRecordActivity.class, bundle);
                            }
                        }
                    });

                } else {
                    tv_sign.setText("已签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_yes);
                    //    tv_specified_learning.setText("查看签名");

                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            if (tv_specified_learning.getText().toString().trim().equals("查看签名")) {
                                Bundle bundle = new Bundle();
                                bundle.putString("signPicUrl", signPicUrl);
                                startActivity(SignCourseActivity.class, bundle);
                            } else if (tv_specified_learning.getText().toString().trim().equals("考试")) {
                                int sn = rowsBean.getSn();
                                SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                String orgId = sp.getString("orgId", "");
                                Bundle bundle = new Bundle();
                                bundle.putString("orgId", orgId);
                                bundle.putInt("qpSn", qpSn);
                                bundle.putInt("learnsn", sn);
                                startActivity(DailyTrainingExaminationItemRecordActivity.class, bundle);
                            }
                        }
                    });

                }
            } else if (rowsBean.getCheckMark() == 1) {
                tv_line_specified.setBackgroundResource(R.color.holetotal_gray);
                img_share.setVisibility(View.VISIBLE);
                tv_check.setVisibility(View.GONE);
//                        tv_check.setText("审核通过");
//                        tv_check.setBackgroundResource(R.drawable.shape_specified_yes);
                tv_yes.setText("已完成");
                tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                tv_sign.setVisibility(View.VISIBLE);
                final String signPicUrl = HelpUtil.judgeStrNull(rowsBean.getSignPicUrl());
                if (signPicUrl.equals("")) {
                    tv_sign.setText("未签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_noorange);
                    //  tv_specified_learning.setText("签名");
                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            if (tv_specified_learning.getText().toString().trim().equals("签名")) {
                                showToast("学习记录不操作签名");
                                return;
                            } else if (tv_specified_learning.getText().toString().trim().equals("考试")) {
                                int sn = rowsBean.getSn();
                                SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                String orgId = sp.getString("orgId", "");
                                Bundle bundle = new Bundle();
                                bundle.putString("orgId", orgId);
                                bundle.putInt("qpSn", qpSn);
                                bundle.putInt("learnsn", sn);
                                startActivity(DailyTrainingExaminationItemRecordActivity.class, bundle);
                            }

                        }
                    });
                } else {
                    tv_sign.setText("已签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_yes);
                    // tv_specified_learning.setText("查看签名");

                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            if (tv_specified_learning.getText().toString().trim().equals("查看签名")) {
                                Bundle bundle = new Bundle();
                                bundle.putString("signPicUrl", signPicUrl);
                                startActivity(SignCourseActivity.class, bundle);
                            } else if (tv_specified_learning.getText().toString().trim().equals("考试")) {
                                int sn = rowsBean.getSn();
                                SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                String orgId = sp.getString("orgId", "");
                                Bundle bundle = new Bundle();
                                bundle.putString("orgId", orgId);
                                bundle.putInt("qpSn", qpSn);
                                bundle.putInt("learnsn", sn);
                                startActivity(DailyTrainingExaminationItemRecordActivity.class, bundle);
                            }
                        }
                    });
                }
            } else if (rowsBean.getCheckMark() == 0) {


                if (rowsBean.getFinishMark() == 1) {
                    tv_line_specified.setBackgroundResource(R.color.holetotal_yellow);
                    img_share.setVisibility(View.VISIBLE);
                    tv_yes.setText("已完成");
                    tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_check.setVisibility(View.GONE);
//                            tv_check.setText("待审核");
//                            tv_check.setBackgroundResource(R.drawable.shape_specified_dai);
                    tv_sign.setVisibility(View.VISIBLE);
                    tv_sign.setText("未签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_noorange);
                    //    tv_specified_learning.setText("签名");
                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            if (tv_specified_learning.getText().toString().trim().equals("签名")) {
                                showToast("学习记录不操作签名");
                                return;
                            }
                        }
                    });

                } else if (rowsBean.getFinishMark() == 2) {
                    tv_line_specified.setBackgroundResource(R.color.holetotal_yellow);
                    img_share.setVisibility(View.VISIBLE);
                    tv_yes.setText("已完成");
                    tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_check.setVisibility(View.GONE);
//                            tv_check.setText("待审核");
//                            tv_check.setBackgroundResource(R.drawable.shape_specified_dai);
                    tv_sign.setVisibility(View.VISIBLE);
                    tv_sign.setText("已签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_yes);
                    //    tv_specified_learning.setText("查看签名");
                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            if (tv_specified_learning.getText().toString().trim().equals("查看签名")) {
                                String signPicUrl = HelpUtil.judgeStrNull(rowsBean.getSignPicUrl());
                                Bundle bundle = new Bundle();
                                bundle.putString("signPicUrl", signPicUrl);
                                startActivity(SignCourseActivity.class, bundle);
                            } else if (tv_specified_learning.getText().toString().trim().equals("考试")) {
                                int sn = rowsBean.getSn();
                                SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                String orgId = sp.getString("orgId", "");
                                Bundle bundle = new Bundle();
                                bundle.putString("orgId", orgId);
                                bundle.putInt("qpSn", qpSn);
                                bundle.putInt("learnsn", sn);
                                startActivity(DailyTrainingExaminationItemRecordActivity.class, bundle);
                            }
                        }
                    });

                } else if (rowsBean.getFinishMark() == 0) {
                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {//未完成
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            if (tv_specified_learning.getText().toString().equals("学习")) {
                                SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                String orgId = sp.getString("orgId", "");
                                int sn = rowsBean.getSn();
                                int actualChLength = rowsBean.getActualChLength();
                                int setChLength = 0;
                                setChLength=(rowsBean.getMiNo()>rowsBean.getSetChLength())?rowsBean.getMiNo():rowsBean.getSetChLength();
                                int checkMark = rowsBean.getCheckMark();
                                int finishMark = rowsBean.getFinishMark();
                                Integer qpSn = rowsBean.getQpSn();


                                Bundle bundle = new Bundle();
                                bundle.putString("orgId", orgId);
                                bundle.putInt("sn", sn);
                                bundle.putString("chName", chName);
                                bundle.putInt("actualChLength", actualChLength);
                                bundle.putInt("setChLength", setChLength);
                                bundle.putInt("checkMark", checkMark);
                                bundle.putInt("finishMark", finishMark);
                                bundle.putInt("chNo", chNo);
                                bundle.putInt("rtype",rowsBean.getOtpSn());
                                if (qpSn == null) {
                                    bundle.putInt("qpSn", 0);
                                } else {

                                    bundle.putInt("qpSn", qpSn);
                                }
                                startActivity(SubSpecifiedLearnRecordActivity.class, bundle);
                            } else if (tv_specified_learning.getText().toString().equals("考试")) {
                                int sn = rowsBean.getSn();
                                SharedPreferences sp = getSharedPreferences("SpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                String orgId = sp.getString("orgId", "");
                                Bundle bundle = new Bundle();
                                bundle.putString("orgId", orgId);
                                bundle.putInt("qpSn", qpSn);
                                bundle.putInt("learnsn", sn);
                                startActivity(DailyTrainingExaminationItemRecordActivity.class, bundle);

                            }

                        }
                    });


                }


            }

            img_share.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    LoginUserBean userInfo = UserManger.getUserInfo();
                    LoginUserBean.DataBean data = userInfo.getData();
                    String userName = data.getUserName();
                    showsharepopwindow(chName, userName);

                }
            });


        }

        private void showsharepopwindow(String chName, final String userName) {

            final String chNamestr = chName.substring(0, 8);

            //设置contentView
            View contentView = LayoutInflater.from(SpecifiedLearnRecordActivity.this).inflate(R.layout.popwindow_share_layout, null);
            final PopupWindow mPopWindow = new PopupWindow(contentView,
                    WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);

            ImageView img_wxin = (ImageView) contentView.findViewById(R.id.img_wxin);
            ImageView img_wxinfriend = (ImageView) contentView.findViewById(R.id.img_wxinfriend);
            LinearLayout le_specified = (LinearLayout) contentView.findViewById(R.id.le_specified);
            le_specified.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mPopWindow.dismiss();
                }
            });
            RelativeLayout re_specified = (RelativeLayout) contentView.findViewById(R.id.re_specified);
            re_specified.setOnClickListener(null);
            mPopWindow.showAtLocation(img_wxin, Gravity.BOTTOM, 0, 0);
            img_wxin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mPopWindow.dismiss();
                    /*UMWeb web = new UMWeb(AppInterfaceConfig.ShareUrl);
                    web.setTitle("我" + userName + "正在使用驾运宝，已完成" + chNamestr + "的日常培训！");
                    web.setThumb(new UMImage(SpecifiedLearnRecordActivity.this, R.drawable.logo_share));
                    web.setDescription("驾运宝，专为互联网道路安全教育而生，快来看看吧！");
                    new ShareAction(SpecifiedLearnRecordActivity.this)
                            .withMedia(web)
                            .setPlatform(SHARE_MEDIA.WEIXIN)//传入平台
                            .setCallback(shareListener)//回调监听器
                            .share();*/
                    WechatShareManager mWechatShareManager= WechatShareManager.getInstance(SpecifiedLearnRecordActivity.this);
                    WechatShareManager.ShareContentWebpage mSharePage = (WechatShareManager.ShareContentWebpage) mWechatShareManager.getShareContentWebpag(
                            "我" + userName + "正在使用驾运宝，已完成" + chNamestr + "的日常培训！",
                            "驾运宝，专为互联网道路安全教育而生，快来看看吧！",
                            AppInterfaceConfig.ShareUrl,
                            bitmap);
                    mWechatShareManager.shareByWebchat(mSharePage, WechatShareManager.WECHAT_SHARE_TYPE_TALK );

                }
            });

            img_wxinfriend.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mPopWindow.dismiss();
                    /*UMWeb web1 = new UMWeb(AppInterfaceConfig.ShareUrl);
                    web1.setTitle("我" + userName + "正在使用驾运宝，已完成" + chNamestr + "的日常培训！");
                    web1.setThumb(new UMImage(SpecifiedLearnRecordActivity.this, R.drawable.logo_share));
                    new ShareAction(SpecifiedLearnRecordActivity.this)
                            .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)//传入平台
                            .withMedia(web1)
                            .setCallback(shareListener)//回调监听器
                            .share();*/
                    WechatShareManager mWechatShareManager= WechatShareManager.getInstance(SpecifiedLearnRecordActivity.this);
                    WechatShareManager.ShareContentWebpage mSharePage = (WechatShareManager.ShareContentWebpage) mWechatShareManager.getShareContentWebpag(
                            "我" + userName + "正在使用驾运宝，已完成" + chNamestr + "的日常培训！",
                            "",
                            AppInterfaceConfig.ShareUrl,
                            bitmap);
                    mWechatShareManager.shareByWebchat(mSharePage, WechatShareManager.WECHAT_SHARE_TYPE_FRENDS );
                }
            });


        }


        /*private UMShareListener shareListener = new UMShareListener() {
            *//**
             * @descrption 分享开始的回调
             * @param platform 平台类型
             *//*
            @Override
            public void onStart(SHARE_MEDIA platform) {

            }

            *//**
             * @descrption 分享成功的回调
             * @param platform 平台类型
             *//*
            @Override
            public void onResult(SHARE_MEDIA platform) {

                Toast.makeText(SpecifiedLearnRecordActivity.this, "分享成功", Toast.LENGTH_LONG).show();
            }

            *//**
             * @descrption 分享失败的回调
             * @param platform 平台类型
             * @param t 错误原因
             *//*
            @Override
            public void onError(SHARE_MEDIA platform, Throwable t) {

                if (t.getMessage().contains("没有安装应用")) {
                    Toast.makeText(SpecifiedLearnRecordActivity.this, "没有安装微信应用", Toast.LENGTH_LONG).show();
                } else {

                    Toast.makeText(SpecifiedLearnRecordActivity.this, "分享失败" + t.getMessage(), Toast.LENGTH_LONG).show();
                }
            }

            *//**
             * @descrption 分享取消的回调
             * @param platform 平台类型
             *//*
            @Override
            public void onCancel(SHARE_MEDIA platform) {

                Toast.makeText(SpecifiedLearnRecordActivity.this, "分享取消", Toast.LENGTH_LONG).show();

            }
        };*/

    }
}
